package cn.itrip.trade.service;

import cn.itrip.mapper.ItripHotelOrder.ItripHotelOrderMapper;
import cn.itrip.mapper.ItripTradeEnds.ItripTradeEndsMapper;
import cn.itrip.pojo.ItripHotelOrder;
import cn.itrip.pojo.ItripTradeEnds;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ItripHoptelOrderServiceImpl implements ItripHoptelOrderService {
    @Resource
    private ItripHotelOrderMapper itripHotelOrderMapper;
    @Resource
    private ItripTradeEndsMapper itripTradeEndsMapper;

    /**
     * 根据订单编号查询
     * @param orderNo
     * @return
     * @throws Exception
     */
    @Override
    public ItripHotelOrder getHotelOrderByOrderNo(String orderNo) throws Exception {
        Map<String,Object> param = new HashMap<>();
        param.put("orderNo",orderNo);
        List<ItripHotelOrder> orders = itripHotelOrderMapper.getItripHotelOrderListByMap(param);
        if(orders !=null && orders.size() == 1){
            return orders.get(0);
        }
        return null;
    }

    /**
     * 修改订单状态
     * @param order
     * @throws Exception
     */
    @Override
    public void updateOrderStatus(ItripHotelOrder order) throws Exception {
        itripHotelOrderMapper.updateItripHotelOrder(order);
        //添加中间扫描表
        ItripTradeEnds ends=new ItripTradeEnds();
        ends.setId(order.getId());
        ends.setOrderNo(order.getOrderNo());
        ends.setFlag("0");
        itripTradeEndsMapper.insertItripTradeEnds(ends);
    }

}
